package cn.flexui.flexuiserver.config;

import cn.flexui.flexuiserver.config.properties.AuthProperties;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.request.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author wanmingyu
 * @create 2024/9/15 17:59
 */
@Configuration
public class OauthConfig {

    @Autowired
    private AuthProperties authProperties;

    @Bean
    public AuthRequest google(){
        return new AuthGoogleRequest(AuthConfig.builder()
                .clientId(authProperties.getGoogle().getClientId())
                .clientSecret(authProperties.getGoogle().getClientSecret())
                .redirectUri(authProperties.getGoogle().getRedirectUri())
//            // 针对国外平台配置代理
//            .httpConfig(HttpConfig.builder()
//                    .timeout(15000)
//                    // host 和 port 请修改为开发环境的参数
//                    .proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 10080)))
//                    .build())
                .build());
    }

    @Bean
    public AuthRequest feishu(){
        return new AuthFeishuRequest(AuthConfig.builder()
                .clientId(authProperties.getFeishu().getClientId())
                .clientSecret(authProperties.getFeishu().getClientSecret())
                .redirectUri(authProperties.getFeishu().getRedirectUri())
                .build());
    }

    @Bean
    public AuthRequest microsoft(){
        return new AuthMicrosoftRequest(AuthConfig.builder()
                .tenantId(authProperties.getMicrosoft().getTenantId())
                .clientId(authProperties.getMicrosoft().getClientId())
                .clientSecret(authProperties.getMicrosoft().getClientSecret())
                .redirectUri(authProperties.getMicrosoft().getRedirectUri())
                .build());
    }

    @Bean
    public AuthRequest github(){
        return new AuthGithubRequest(AuthConfig.builder()
                .clientId(authProperties.getGithub().getClientId())
                .clientSecret(authProperties.getGithub().getClientSecret())
                .redirectUri(authProperties.getGithub().getRedirectUri())
                .build());
    }
}
